package com.hwd.srb.core.controller.admin;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hwd.srb.common.constant.Constants;
import com.hwd.srb.common.result.R;
import com.hwd.srb.core.pojo.entity.Borrower;
import com.hwd.srb.core.pojo.vo.BorrowerApprovalVO;
import com.hwd.srb.core.pojo.vo.BorrowerDetailVO;
import com.hwd.srb.core.service.BorrowerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author 黄伟东/Victor
 * @since 2022-03-10
 */
@RestController
@RequestMapping("/admin/core/borrower")
@ApiModel("后台管理积分等级接口")
@Api(tags = "借款管理")
@Slf4j
public class AdminBorrowerController {

    @Resource
    private BorrowerService borrowerService;

    /**
     * 借款额度审核
     *
     * @param borrowerApprovalVO 借款人审核数据对象
     * @return com.hwd.srb.common.result.R
     */
    @ApiOperation("借款额度审核")
    @PostMapping("/approval")
    public R approval(@ApiParam(value = "借款人审核数据对象", required = true)
                      @RequestBody BorrowerApprovalVO borrowerApprovalVO) {

        // 调用业务层增删改查
        borrowerService.approval(borrowerApprovalVO);

        return R.ok();
    }

    /**
     * 根据id查询借款人详情(额度申请)
     *
     * @param borrowerId 借款人id
     * @return com.hwd.srb.common.result.R
     */
    @ApiOperation("借款人详情(额度申请)")
    @GetMapping("show/{id}")
    public R show(@ApiParam(value = "借款人id", required = true, example = "1")
                  @PathVariable("id") Long borrowerId) {

        BorrowerDetailVO borrowerDetailVO = borrowerService.show(borrowerId);

        return R.ok().data("borrowerDetailVO", borrowerDetailVO);
    }

    /**
     * 根据关键字查询借款人列表(额度申请)
     *
     * @param page    当前页
     * @param limit   每页多少条
     * @param keyword 关键字
     * @return com.hwd.srb.common.result.R
     */
    @ApiOperation("借款人列表(额度申请)")
    @GetMapping("list/{page}/{limit}")
    public R list(@ApiParam(value = "当前页码", required = true, example = "1") @PathVariable("page") Long page,
                  @ApiParam(value = "每页记录数", required = true, example = "10") @PathVariable("limit") Long limit,
                  @ApiParam(value = "关键字", required = true) String keyword) {
        // 分页参数，page，size
        Page<Borrower> pageParam = new Page<>(page, limit);

        // 调用业务层方法执行分页查询
        IPage<Borrower> pageModel = borrowerService.listPage(pageParam, keyword);

        return R.ok().data(Constants.PAGE_MODEL, pageModel);
    }

}

